package com.epalmpay.controller.apiShopApp;

import com.epalmpay.commom.BaseController;
import com.epalmpay.enumdef.BizEnum;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.service.app.IAppShopService;
import com.epalmpay.service.sms.ISMSService;
import com.epalmpay.service.weixin.ITokenService;
import com.epalmpay.util.Const;
import com.epalmpay.util.RedisUtil;
import com.epalmpay.util.Response;
import com.epalmpay.util.Tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import redis.clients.jedis.Jedis;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * 首页
 * Created by Administrator on 2018/2/26.
 */
@Controller
@RequestMapping(value="/app/shop")
public class ShopIndexApiController extends BaseController{


    @Resource
    private ITokenService tokenService;

    @Resource
    private IAppShopService appShopService;

    @Autowired
    protected ISMSService smsService;

    /**
     *  暂时不用
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/firstPage", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response firstPage(String shopId, String token) throws Exception {
        logBefore(logger, "首页");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("商户编号", shopId);
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
//        Boolean flag = tokenService.checkToken(shopId, token);
//        if (!flag) {
//            return Response.getError(Response.LOGIN_CODE,"登录失效");
//        }
        try {
            Response response = appShopService.firstPage(shopId);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }

    /**
     * 简化版首页
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/simpleIndex", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response simpleIndex(String shopId, String token) throws Exception {
        logBefore(logger, "首页");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("商户编号", shopId);
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
//        Boolean flag = tokenService.checkToken(shopId, token);
//        if (!flag) {
//            return Response.getError(Response.LOGIN_CODE,"登录失效");
//        }
        try {
            Response response = appShopService.simpleIndex(shopId);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }




    /**
     * 发送短信验证码
     * @param type
     * @param phone
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/appSendCode", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public Response sendCode(String phone,String type) throws Exception {
        logBefore(logger, "发送短信验证码");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("手机号码", phone);
        resultMap.put("短信类型", type);
        String nullParam=Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam+"不能为空");
        }
        Map<String,String> map = new HashMap<String,String>();
        Date date=new Date();
        RedisUtil redisUtil = new RedisUtil();
        Jedis jedis = redisUtil.getJedis();
        //短信验证码2分钟发送一次 验证码有效时间30分钟
        /*Date verifyDate=(Date)Const.CacheMapObject.get(Const.SESSION_TiME_CODE+phone+type);
        if(verifyDate!=null){
            //当前时间120秒后
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(verifyDate);
            calendar.add(Calendar.SECOND, 120);
            if(calendar.getTime().after(date)){
                return Response.getError("2分钟内只能发送1条校验码。");
            }
        }*/
        Long verifyDate = jedis.ttl(Const.SESSION_PHONE_CODE+phone+type);
        if(verifyDate!=null){
            if(verifyDate >= 1680){//如果剩余生成时间大于1680秒，则抛出异常
                return Response.getError("2分钟内只能发送1条校验码。");
            }
        }
        try {
            String code="true".equals("false") ? "000000" : String.format("%.0f",(Math.random()*9+1)*100000);
            this.logger.info("---验证码---:"+code);
            Map<String, String> params=new HashMap<String, String>();
            boolean flag = false;
            flag = smsService.sendRegionCode(null, code, BizEnum.SMSTemplateType.temp_SMS_104630027.getType(), phone, params);
            if(flag){
                //Const.CacheMapObject.put(Const.SESSION_PHONE_CODE+phone+type,code);
                //Const.CacheMapObject.put(Const.SESSION_TiME_CODE+phone+type, date);
                jedis.setex(Const.SESSION_PHONE_CODE+phone+type, 1800, code);
            }
            jedis.quit();
            return Response.getSuccess(map);
        } catch (Exception e) {
            e.printStackTrace();
            return Response.getError("验证码发送异常");
        }

    }



    /**
     * 我的商博士
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/index", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response index(String shopId, String token) throws Exception {
        logBefore(logger, "首页");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("商户编号", shopId);
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.index(shopId);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }


    /**
     * 钱包余额
     * @param shopId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/shopBalance", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response shopBalance(String shopId) throws Exception {
        logBefore(logger, "首页");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("商户编号", shopId);
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.shopBalance(shopId);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }


    /**
     *
     * 结算记录
     * @param shopId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/monthSettlementInfo", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response monthSettlementInfo(String shopId,String statisDate) throws Exception {
        logBefore(logger, "结算记录");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("商户编号", shopId);
        resultMap.put("日期", statisDate);
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.monthSettlementInfo(shopId,statisDate);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }

    /**
     *
     * 结算详情  待完善
     * @param shopId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/daySettlementDetail", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response daySettlementDetail(String shopId,String statisDate) throws Exception {
        logBefore(logger, "结算记录");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("商户编号", shopId);
        resultMap.put("日期", statisDate);
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.daySettlementDetail(shopId,statisDate);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }


    /**
     *
     * 商户交易记录
     * @param shopId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/tradeList", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response tradeList(String shopId,String statisDate,Integer transactionType,Integer payType,Integer type,Integer pageNo,Integer pageSize) throws Exception {
        logBefore(logger, "商户交易记录");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("商户编号", shopId);
        resultMap.put("收款途径", type+"");
        resultMap.put("起始页", pageNo+"");
        resultMap.put("每页显示条数", pageSize+"");
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.tradeList(shopId,statisDate,transactionType,payType,type,pageNo,pageSize);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }



    /**
     *  提现账户信息
     * @param shopId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/shopDrawBankInfo", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response shopDrawBankInfo(String shopId) throws Exception {
        logBefore(logger, "提现账户信息");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("商户编号", shopId);
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.shopDrawBankInfo(shopId);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }

    /**
     *  提现记录
     * @param shopId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/drawList", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response drawList(String shopId,String groupId,Integer pageNo,Integer pageSize) throws Exception {
        logBefore(logger, "提现账户信息");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("商户编号", shopId);
        resultMap.put("起始页", pageNo+"");
        resultMap.put("每页显示条数", pageSize+"");
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.drawList(shopId,groupId,pageNo,pageSize);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }
    /**
     *  提现记录详情
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/detailDraw", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response detailDraw(String id) throws Exception {
        logBefore(logger, "提现记录详情");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("提现记录id", id);
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.detailDraw(id);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }

    /**
     *  发起提现
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/goWithdrawal", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response goWithdrawal(String shopId,Integer balance ,Integer amount,String phone,String code,String type) throws Exception {
        logBefore(logger, "提现记录详情");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("提现记录id", shopId);
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            RedisUtil redisUtil = new RedisUtil();
            Jedis jedis = redisUtil.getJedis();
            String codemessage = jedis.get(Const.SESSION_PHONE_CODE+phone+type);
            //String codemessage=(String) Const.CacheMapObject.get(Const.SESSION_PHONE_CODE+phone+type);
            logBefore(logger, "原验证码"+codemessage);
            if(Tools.isEmpty(codemessage)||!codemessage.equals(code)){
                return Response.getError("验证码输入错误");
            }
            Response response = appShopService.updateWithdrawal(shopId,balance,amount);
            //Const.CacheMapObject.remove(Const.SESSION_PHONE_CODE+phone+type);
            jedis.del(Const.SESSION_PHONE_CODE+phone+type);
            jedis.quit();
            resultMap.put("message", "处理成功");
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }



    /**
     *  积分余额
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/shopBonusBalance", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response shopBonusBalance(String shopId) throws Exception {
        logBefore(logger, "积分余额");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("商户id", shopId);
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.shopBonusBalance(shopId);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }



    /**
     *  积分发放月报表
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/sendShopBonusList", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response sendShopBonusList(String shopId,Integer pageNo,Integer pageSize) throws Exception {
        logBefore(logger, "积分发放月报表");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("商户id", shopId);
        resultMap.put("起始页", pageNo+"");
        resultMap.put("每页显示条数", pageSize+"");
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.sendShopBonusList(shopId,pageNo,pageSize);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }

    /**
     *  积分核销报表
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/shopMonthBonusVeriftyList", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response shopMonthBonusVeriftyList(String shopId,Integer pageNo,Integer pageSize) throws Exception {
        logBefore(logger, "积分核销报表");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("商户id", shopId);
        resultMap.put("起始页", pageNo+"");
        resultMap.put("每页显示条数", pageSize+"");
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.shopMonthBonusVeriftyList(shopId,pageNo,pageSize);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }






    /**
     *  积分发放月明细报表
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/monthShopSendBonusDetail", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response monthShopSendBonusDetail(String shopId,String stringDate,Integer pageNo,Integer pageSize) throws Exception {
        logBefore(logger, "积分发放月明细报表");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("商户id", shopId);
        resultMap.put("发放时间", stringDate);
        resultMap.put("起始页", pageNo+"");
        resultMap.put("每页显示条数", pageSize+"");
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.monthShopSendBonusDetail(shopId,stringDate,pageNo,pageSize);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }



    /**
     *  积分核销月明细报表
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/monthVerifyDetail", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response monthVerifyDetail(String shopId,String stringDate,Integer pageNo,Integer pageSize) throws Exception {
        logBefore(logger, "积分发放月明细报表");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("商户id", shopId);
        resultMap.put("发放时间", stringDate);
        resultMap.put("起始页", pageNo+"");
        resultMap.put("每页显示条数", pageSize+"");
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.monthVerifyDetail(shopId,stringDate,pageNo,pageSize);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }



    /**
     *  积分发放日明细报表
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/daySendBonusDetail", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response daySendBonusDetail(String shopId,String statisDate,Integer pageNo,Integer pageSize) throws Exception {
        logBefore(logger, "积分发放报表");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("商户id", shopId);
        resultMap.put("发放时间", statisDate+"");
        resultMap.put("起始页", pageNo+"");
        resultMap.put("每页显示条数", pageSize+"");
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.daySendBonusDetail(shopId,statisDate,pageNo,pageSize);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }

    /**
     *  积分发放日明细报表
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/dayVerifyDetail", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response dayVerifyDetail(String shopId,String statisDate,Integer pageNo,Integer pageSize) throws Exception {
        logBefore(logger, "积分发放报表");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("商户id", shopId);
        resultMap.put("发放时间", statisDate+"");
        resultMap.put("起始页", pageNo+"");
        resultMap.put("每页显示条数", pageSize+"");
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.dayVerifyDetail(shopId,statisDate,pageNo,pageSize);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }

    /**
     *  积分变更记录
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/bonusChange", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response bonusChange(String shopId) throws Exception {
        logBefore(logger, "积分变更记录");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("商户id", shopId);
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.bonusChange(shopId);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }

    /**
     *  积分规则
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/shopBonusRule", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response shopBonusRule(String shopId,String groupId) throws Exception {
        logBefore(logger, "积分规则");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("商户id", shopId);
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.shopBonusRule(shopId,groupId);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }



    /**
     *  积分变更记录详情
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/adjustBonusDetail", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response adjustBonusDetail(String id,Integer type) throws Exception {
        logBefore(logger, "积分变更记录详情");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("id", id);
        resultMap.put("id类型", type+"");
//        resultMap.put("变更类型", userType+"");
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.adjustBonusDetail(id,type);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }


    /**
     *  店铺详情
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/shopDetail", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response shopDetail(String shopId) throws Exception {
        logBefore(logger, "店铺详情");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("商户id", shopId);
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.shopDetail(shopId);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }

    /**
     *  活动列表
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/activityList", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response activityList(String shopId,Integer type,Integer pageNo,Integer pageSize) throws Exception {
        logBefore(logger, "活动列表");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("商户id", shopId);
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.activityList(shopId,type,pageNo,pageSize);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }



    /**
     *  活动详情
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/activityDetail", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response activityDetail(String activityId) throws Exception {
        logBefore(logger, "活动详情");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("活动id", activityId);
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.activityDetail(activityId);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }

    /**
     *  活动内容
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/activityContent", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response activityContent(String shopId,String activityId,Integer sendType) throws Exception {
        logBefore(logger, "活动内容");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("活动id", activityId);
        resultMap.put("商户id", shopId);
        resultMap.put("赠送类型",sendType+"");
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.activityContent(shopId,activityId,sendType);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }

    /**
     * 活动介绍
     * @param activityId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/activityMemo", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response activityMemo(String activityId) throws Exception {
        logBefore(logger, "活动介绍");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("活动id", activityId);
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.activityMemo(activityId);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }


    /**
     * 活动效果统计
     * @param activityId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/shopEffect", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response shopEffect(String activityId,String shopId,Integer sendType ,Integer pageNo,Integer pageSize) throws Exception {
        logBefore(logger, "活动效果统计");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("活动id", activityId);
        resultMap.put("商户id", shopId);
        resultMap.put("赠送类型", sendType+"");
        resultMap.put("起始页", pageNo+"");
        resultMap.put("每页显示条数", pageSize+"");
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.shopEffect(activityId,shopId,sendType,pageNo,pageSize);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }


    /**
     * 日活动详细列表
     * @param activityId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/dayActivityDetail", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response dayActivityDetail(String activityId,String shopId,Integer sendType ,String statisDate,Integer pageNo,Integer pageSize) throws Exception {
        logBefore(logger, "日活动详细列表");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("活动id", activityId);
        resultMap.put("商户id", shopId);
        resultMap.put("赠送类型", sendType+"");
        resultMap.put("起始页", pageNo+"");
        resultMap.put("每页显示条数", pageSize+"");
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.dayActivityDetail(activityId,shopId,sendType,statisDate,pageNo,pageSize);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }







    /**
     *  优惠券列表
     * @param type
     * @param shopId
     * @param pageNo
     * @param pageSize
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/couponList", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response couponList(Integer type,String shopId,Integer pageNo,Integer pageSize) throws Exception {
        logBefore(logger, "优惠券列表");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("活动id", shopId);
        resultMap.put("活动类型", type+"");
        resultMap.put("起始页", pageNo+"");
        resultMap.put("每页显示条数", pageSize+"");
        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.couponList(shopId,type,pageNo,pageSize);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }




    /**
     *  分润管理
     * @param shopId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/profitManage", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response profitManage(String shopId) throws Exception {
        logBefore(logger, "分润管理");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("门店id", shopId);

        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.profitManage(shopId);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }


    /**
     *  分润明细列表
     * @param shopId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/shopMonthDetailList", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response shopMonthDetailList(String shopId,Integer pageNo,Integer pageSize) throws Exception {
        logBefore(logger, "分润明细列表");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("门店id", shopId);
        resultMap.put("起始页", pageNo+"");
        resultMap.put("每页显示条数", pageSize+"");

        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.shopMonthDetailList(shopId,pageNo,pageSize);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }

    /**
     *  明细列表
     * @param shopId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/profitDayList", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response profitDayList(String shopId,String statisDate,Integer pageNo,Integer pageSize) throws Exception {
        logBefore(logger, "分润明细列表");
        HashMap<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("门店id", shopId);
        resultMap.put("统计月份", statisDate);
        resultMap.put("起始页", pageNo+"");
        resultMap.put("每页显示条数", pageSize+"");

        String nullParam = Response.checkNull(resultMap);
        if (null != nullParam) {
            return Response.getError(nullParam + "不能为空");
        }
        try {
            Response response = appShopService.profitDayList(shopId,statisDate,pageNo,pageSize);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }










}
